/**
 * JAVACC DEMO 1.0
 */
package com.apache.info.service.plugins;

import com.apache.api.vo.ParamsVo;
import com.apache.cache.util.Validator;
import com.apache.info.entity.PubInfoStatistics;
import com.apache.info.manager.PubInfoStatisticsManager;

import java.util.Map;

/**
 * description:  主子表插入操作
 *
 * @author iussoft 创建时间：2016-10-15
 */
public class SubInsertInfoPluginImpl extends AbstractSubInfoPlugin {

    private PubInfoStatisticsManager pubInfoStatisticsManager;

    /**
     * TODO 简单描述该方法的实现功能（可选）.
     *
     * @see AbstractSubInfoPlugin#doInvoke(ParamsVo)
     */
    protected Object doInvoke(ParamsVo vo) {
        String mark = "false";
        if (Validator.isNull(String.valueOf(vo.getParams("dyncSql")))) {//直接执行sql查询
            String sql = this.getDynicSql(vo, 1, String.valueOf(vo.getParams("mainSortCode")),
                    String.valueOf(vo.getParams("mainTableName")));
            String subSql = this.getDynicSql(vo, 1, String.valueOf(vo.getParams("subSortCode")),
                    String.valueOf(vo.getParams("subTableName")));
            vo.setParams("dyncSql", sql);
            vo.setParams("subDyncSql", subSql);
        }
        mark = InfoReleaseManager.saveInfo(vo);
        if ("true".equals(mark) && "true"
                .equals(String.valueOf(vo.getParams("flagInfoStatistics")))) {//添加统计信息
            Map map = vo.getParams();
            ParamsVo pvo = new ParamsVo();
            PubInfoStatistics ps = new PubInfoStatistics();
            ps.setInfoId(Validator.generate());
            ps.setInfoUser(String.valueOf(map.get("createUser")));
            ps.setObjId(String.valueOf(map.get("infoId")));
            ps.setSortId(String.valueOf(vo.getParams("mainSortCode")));
            pvo.setObj(ps);
            pubInfoStatisticsManager.saveInfo(pvo);
        }
        return mark;
    }

    public void setPubInfoStatisticsManager(PubInfoStatisticsManager pubInfoStatisticsManager) {
        this.pubInfoStatisticsManager = pubInfoStatisticsManager;
    }

}
